package com.base.pig.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ProjectName intelligent-city
 * @Package com.pig4cloud.pig.lab.util
 * @ClassName DateUtils
 * @Description 时间函数处理
 * @Company lab
 * @Author wangw
 * @Date 2020/6/29 0029 14:45
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 * @Version 1.0.0
 */
public class DateUtils {

    /**
     * @param month : 月份数
     * @return
     * @Title 获取当前时间前几个月
     * @Description
     * @author wangw
     * @date 2020/6/29 0029 14:15
     */
    public static String getLastMonths(int month) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, -month);
        Date m = c.getTime();
        return sdf.format(m);
    }
    
    /** 
     * @Title 获取年份
     * @Description
     * @param lastYearCount : 过去年数,表示过去x年
     * @return
     * @author wangw
     * @date 2020/7/2 0002 11:11
    */
    public static String getLastYear(int lastYearCount){
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, -1);
        Date y = c.getTime();
        return format.format(y);
    }
}